package tech.aistar.controller.center;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import tech.aistar.entity.*;
import tech.aistar.service.center.IUserInfoService;
import tech.aistar.service.client.IUserService;
import tech.aistar.service.demand.IPictureService;
import tech.aistar.vo.IdCardDataVo;
import tech.aistar.vo.PictureVo;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.List;

/**
 * Created by 23827 on 2019/10/16.
 */
@Controller
@RequestMapping("/information")
public class CenterInformationController {
    @Autowired
    private IUserInfoService iUserInfoService;
    @Autowired
    private IPictureService iPictureService;
    @RequestMapping("/list")
    public String list(){
        return "/user/centerInformation";
    }

    @RequestMapping("/add")
    @ResponseBody
    public Result add(@RequestBody UserInfo userInfo, HttpSession session){

               System.out.println(userInfo);
        Integer uid = (Integer) session.getAttribute("userId");
        System.out.println(uid);

        UserInfo userInfo1 =new UserInfo();
        userInfo1.setId(uid);
        userInfo1.setName(userInfo.getName());
        iUserInfoService.updateOne(userInfo1);


        return new Result(CodeStatus.OK,true,"添加成功");
    }

    @RequestMapping("/show")
    public String show(Model model,HttpSession session){
        Integer uid = (Integer) session.getAttribute("userinfo_id");
        Picture p = iPictureService.findPathById(uid);
//        p.getPath();
        model.addAttribute("p",p);
        UserInfo userInfo = iUserInfoService.ById(uid);
        model.addAttribute("userInfo",userInfo);
        return "/user/centerInformation";
    }
}
